<!DOCTYPE html>
<html lang="zc-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        //给一个数字数组，该数组中有很多数字0，将不为0的数据存入到一个新的数组中
        // let arr2 = []
        // let arr = [10,0,20,0,30,0,40]
        // for (let i=0;i<arr.length;i++) {
        //     if (arr[i] !==0) {
        //         console.log(arr[i]);
        //        arr2.push(arr[i])
        //     }
        // }
        // document.write(arr2);

        let arr = []
//2.循环遍历
while( arr.length < 5 ){
    //输入年龄
    let num = +prompt(`请输入第${arr.length+1}个人有效年龄`)
    //判断是否有效
    if( num > 0 && num < 100){
        //添加到数组
        arr.push(num)
    }
}
   console.log(arr)
    </script>
</body>
</html>